<?php defined( '_VALID_MOS' ) or die( include_once("../../404.php") );
$sql = "SELECT `session`.`Title` as `map_path`, `news`.`News_Id`, `news`.`Title`, `news`.`alias`, `news`.`Description`, `news`.`img_file`,`news`.`img_status`,
		Date_Format(`news`.`Date`, '%d/%m/%Y lúc: %h:%m') AS `date_add`, DateDiff(CurDate(), `news`.`Date`) AS `Expires`
		FROM `news` INNER JOIN `category` ON `category`.`Cat_Id` = `news`.`CatID` INNER JOIN `session` ON `session`.`Ses_Id` = `category`.`SesID`
		WHERE `category`.`alias` = ? AND `news`.`Status` = 1
		ORDER BY `news`.`Order` DESC"; 
$cmd = $mysqli->prepare($sql);
$cmd->bind_param("s", $_GET["alias"]);
$cmd->execute() or die($mysqli->error);
$cmd->bind_result($map_path, $News_Id, $Title, $alias, $Description, $img_file, $img_status, $date_add, $Expires);
$cmd->store_result();
include("protected/front_end_paging.php");

if(!isset($_GET["page"])) $p = 1; else $p = $_GET["page"];
$pager = Pager::getPagerData($cmd->num_rows, 5, $p);
$i = 1;
?>
					
<div id="box_category">
<div id="sub_box_category">
	<div class="bg_tt_right"><div class="bg_tt_left"><div class="bg_tt"><div class="text_tt"><?php echo $map_path;?></div></div></div></div>
	<div id="sub_box_category1">
		<div class="ct_right">
			<div class="ct_left">
				<div class="ct">
					<?php while($cmd->fetch()){
						if($i > $pager->offset && $i <= $pager->limit){ ?>
							<div class="category_content">
								<div class="title"><a href="<?php echo "./com_content/article/$alias/" . $_GET["item"] . ".csp"; ?>"><?php echo $Title; ?></a></div>
								<div class="date">Cập nhật ngày: <?php echo $date_add; ?></div>
								<div class="content">
									<?php if ($img_status) { echo "<div class=\"news_img\"><a href=./com_content/article/$alias/" . $_GET["item"] . ".csp><img width=\"130\" height=\"100\" src=\"$img_file\"></a></div>";}?>
									<div class="news_content"><?php echo $Description; ?></div>
									<div class=clear></div>
								</div>
								<div class=clear></div>
							</div>
						<?php }
						$i++;
					} ?>
					
					<?php if($cmd->num_rows > 5){
						//if($pager->offset>5){$startposition = $pager->offset + 5;} else {$startposition = $pager->offset+1;}
						$startposition = $pager->offset + 5;
						$sql1 = "SELECT `news`.`News_Id`, `news`.`Title`, `news`.`alias`, Date_FORMAT(`news`.`Date`, '%d/%m/%Y') As Date
						FROM `category` INNER JOIN `news` ON `category`.`Cat_Id` = `news`.`CatID`
						WHERE `category`.`alias` = ? AND `news`.`Status` = 1 
						Order by `news`.`Order` desc limit $startposition,10";
						$cmd1 = $mysqli->prepare($sql1);
						$cmd1->bind_param("s", $_GET["alias"]);
						$cmd1->execute() or die($mysqli->error);
						$cmd1->bind_result($subId, $subTitle, $subalias, $subnews_date);
						$cmd1->store_result(); ?>
						<div class="othernews_title">Các tin khác</div>
						<div class="othernews_text">
							<ul>
								<?php while($cmd1->fetch()){
									echo "<li><a href=\"./com_content/article/$subalias/".$_GET["item"].".csp\">$subTitle</a> ($subnews_date)</li>";
								} ?>
							</ul>
						</div>
						<div class="util_bottom">
							<ul>
								<li><a href="<?php echo $_SERVER['REQUEST_URI'] . "#";?>"><img src="templates/default/images/icon_dautrang.gif"></a></li>
							</ul>
						</div>					
						
					<?php 
						echo "<div class=\"page_num\"><ul>";
						echo $pager->paging .  "<li> Trang " . $pager->page . " của " . $pager->numPages . "</li>"; 
						echo "</ul></div>";
					} ?>
					
					</div>
				</div>
			</div>
			<div class="bg_bt_right"><div class="bg_bt_left"><div class="bg_bt"><div class="text_bt">&nbsp;</div></div></div></div>
		</div>
	</div>
	<div class="clear"></div>
</div>